package com.example.intermediate_control;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
//复选框demo测试

public class CheckBoxTestActivity extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_check_box_test);
        CheckBox checkBox1 = findViewById(R.id.checkbox_one);
        CheckBox checkBox2 = findViewById(R.id.checkbox_two);
        checkBox1.setOnCheckedChangeListener(this);
        checkBox2.setOnCheckedChangeListener(this);
    }

    @Override
    public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
        String result = String.format("你%s了当前按钮", b ? "勾选" : "取消勾选");
        compoundButton.setText(result);
    }
}